*****Preparation 
***Set scheme for figures
set scheme plotplain

***To perform the analyses of the article, keep self-identified whites only
keep if race==1

***Creating relevant variables for use in analyses
**Different versions of the treatment variable (message)
recode message (1=1) (3=1) (2=2) (4=2) (5=5), gen(message_neutralvsmoral)
label define message_neutralvsmoral 1"neutral" 2"moral" 5"control"
label values message_neutralvsmoral message_neutralvsmoral

recode message (1=1) (2=1) (3=2) (4=2) (5=0), gen(argtype)
label define argtype 1"economy" 2"culture" 0"control"
label values argtype argtype

**Moral conviction: higher values = more morally convicted
alpha q10 q11
gen moral_conviction_index = ((q10+q11)-2)/8

**Attitude extremity: higher values = more extreme immigration attitude (postive or negative)
gen im_extreme = 0 if q9==4
replace im_extreme = 1 if q9==3 | q9==5
replace im_extreme = 2 if q9==2 | q9==6
replace im_extreme = 3 if q9==1 | q9==7

**Social distance - correlation and factor analyses as preparation for constructing indices
*Appendix 1, Table A1.3.
corr distance_pres distance_mayor distance_neighbour distance_colleague distance_family distance_spouse distance_friend distance_shopowner distance_teacher

*Appendix 1, Tables A1.4, A1.5.
factor distance_pres distance_mayor distance_neighbour distance_colleague distance_family distance_spouse distance_friend distance_shopowner distance_teacher
rotate

**Social distance political leaders
*First, rescale so higher values = more distance (less happy with person having different opinion)
recode distance_pres (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_mayor (1=5) (2=4) (3=3) (4=2) (5=1)
alpha distance_pres distance_mayor
*Generate index
gen distance_polleader = ((distance_pres + distance_mayor)-2)/8

**Social distance social interaction partners
*First, rescale so higher values = more distance (less happy with person having different opinion)
recode distance_neighbour (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_colleague (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_family (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_spouse (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_friend (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_shopowner (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_teacher (1=5) (2=4) (3=3) (4=2) (5=1)
alpha distance_neighbour distance_colleague distance_family distance_spouse distance_friend distance_shopowner distance_teacher
*Generate index
gen distance_personalrelations = ((distance_neighbour + distance_colleague + distance_family + distance_spouse + distance_friend + distance_shopowner + distance_teacher)-7)/28

**Manipulation check status
gen mani_check = .
replace mani_check = 1 if q14==1 & q15==1 
replace mani_check = 3 if message==5
recode mani_check (1=1) (3=3) (else=2)
label define manipulation 1"passed" 2"not passed" 3"control"
label values mani_check manipulation

recode mani_check (1=1) (2=2) (3=1), gen(mani_check2)
label values mani_check2 manipulation

*****Analysis Part I: Direct effects of message exposure on the four outcomes
***Figure 1 (U.S. results), Note: Regression output produced in the below analyses is found in Appendix 2, Table A2.1. Coefficient plots are found in Figure 1
reg moral_conviction_index ib5.message i.mani_check2
coefplot, drop(_cons 2.mani_check2) levels (95 90) xline(0) xscale(range(-.1 .15))

reg im_extreme ib5.message i.mani_check2
coefplot, drop(_cons 2.mani_check2) levels (95 90) xline(0) xscale(range(-.3 .3))

reg distance_polleader ib5.message i.mani_check2
coefplot, drop(_cons 2.mani_check2) levels (95 90) xline(0) xscale(range(-.05 .1))

reg distance_personalrelations ib5.message i.mani_check2
coefplot, drop(_cons 2.mani_check2) levels (95 90) xline(0) xscale(range(-.05 .1))

***Appendix 2 comparison plots
**Figure A2.1.
reg moral_conviction_index ib5.message i.mani_check2
margins i.message, pwcompare(effects)
marginsplot, horizontal unique recast(scatter) yscale(reverse) xline(0) xscale(range(-.15 .15))

**Figure A2.3.
reg im_extreme ib5.message i.mani_check2
margins i.message, pwcompare(effects)
marginsplot, horizontal unique recast(scatter) yscale(reverse) xline(0) xscale(range(-.4 .4))

**Figure A2.5.
reg distance_polleader ib5.message i.mani_check2
margins i.message, pwcompare(effects)
marginsplot, horizontal unique recast(scatter) yscale(reverse) xline(0) xscale(range(-.15 .15))

**Figure A2.7
reg distance_personalrelations ib5.message i.mani_check2
margins i.message, pwcompare(effects)
marginsplot, horizontal unique recast(scatter) yscale(reverse) xline(0) xscale(range(-.15 .15))

***Appendix 4. Mediation analysis
*Recoding the treatment variable so the control condition has the value of "0"
recode message (1=1) (2=2) (3=3) (4=4) (5=0), gen(message0)
label values message0 vignette

**Mediation analyses as basis for matrices for creating Figure A4.1., Distance political leaders
*Economy
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_polleader moral_conviction_index message0 mani_check2) if message0==0 | message0==1, mediate(moral_conviction_index) treat(message0 0 1) sims(1000) seed(20)

matrix distancepol_eco = (.0482957,-.0046987 \ -.0029832,-.0200149 \ .1018709,.0095838)
matrix colnames distancepol_eco = totaleff acme
matrix rownames distancepol_eco = mean lb95 ub95
matrix list distancepol_eco 

*Economy-moral
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_polleader moral_conviction_index message0 mani_check2) if message0==0 | message0==2, mediate(moral_conviction_index) treat(message0 0 2) sims(1000) seed(20)

matrix distancepol_moraleco = (.059469,.0081937 \ .0103778,-.0047916 \ .1094452,.0226203)
matrix colnames distancepol_moraleco = totaleff acme
matrix rownames distancepol_moraleco = mean lb95 ub95
matrix list distancepol_moraleco 

*Culture
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_polleader moral_conviction_index message0 mani_check2) if message0==0 | message0==3, mediate(moral_conviction_index) treat(message0 0 3) sims(1000) seed(20)

matrix distancepol_cul = (.0211289,.0094201 \ -.0299269,-.0039929 \ .0731596,.0244802)
matrix colnames distancepol_cul = totaleff acme
matrix rownames distancepol_cul = mean lb95 ub95
matrix list distancepol_cul 

*Culture-moral
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_polleader moral_conviction_index message0 mani_check2) if message0==0 | message0==4, mediate(moral_conviction_index) treat(message0 0 4) sims(1000) seed(20)

matrix distancepol_moralcul = (.03585946,.0174035 \ -.011763,.0032787 \ .0901175,.0336459)
matrix colnames distancepol_moralcul = totaleff acme
matrix rownames distancepol_moralcul = mean lb95 ub95
matrix list distancepol_moralcul

*Figure A4.1. based on above mediation analysis output
coefplot (matrix(distancepol_eco), ci((2 3))) (matrix(distancepol_moraleco), ci((2 3))) (matrix(distancepol_cul), ci((2 3))) (matrix(distancepol_moralcul), ci((2 3))), xline(0) xscale(range(-.1 .1))

**Mediation analyses as basis for matrices for creating Figure A4.3., Distance social interaction partners
*Economy
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_personalrelations moral_conviction_index message0 mani_check2) if message0==0 | message0==1, mediate(moral_conviction_index) treat(message0 0 1) sims(1000) seed(20)

matrix distancepers_eco = (.0060612,-.0021104 \ -.0408622,-.0121522 \ .0540297,.00678)
matrix colnames distancepers_eco = totaleff acme
matrix rownames distancepers_eco = mean lb95 ub95
matrix list distancepers_eco 

*Economy-moral
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_personalrelations moral_conviction_index message0 mani_check2) if message0==0 | message0==2, mediate(moral_conviction_index) treat(message0 0 2) sims(1000) seed(20)

matrix distancepers_moraleco = (.0406657,.00604 \ -.0042314,-.0045674 \ .0862667,.0179967)
matrix colnames distancepers_moraleco = totaleff acme
matrix rownames distancepers_moraleco = mean lb95 ub95
matrix list distancepers_moraleco 

*Culture
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_personalrelations moral_conviction_index message0 mani_check2) if message0==0 | message0==3, mediate(moral_conviction_index) treat(message0 0 3) sims(1000) seed(20)

matrix distancepers_cul = (.0575564,.0071937 \ .0119617,-.001751 \ .1041581,.0179937)
matrix colnames distancepers_cul = totaleff acme
matrix rownames distancepers_cul = mean lb95 ub95
matrix list distancepers_cul 

*Culture-moral
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_personalrelations moral_conviction_index message0 mani_check2) if message0==0 | message0==4, mediate(moral_conviction_index) treat(message0 0 4) sims(1000) seed(20)

matrix distancepers_moralcul = (.054546,.0124771 \ .0094138,.0032493 \ .1009482,.024386)
matrix colnames distancepers_moralcul = totaleff acme
matrix rownames distancepers_moralcul = mean lb95 ub95
matrix list distancepers_moralcul

*Figure A4.3. based on above mediation analysis output
coefplot (matrix(distancepers_eco), ci((2 3))) (matrix(distancepers_moraleco), ci((2 3))) (matrix(distancepers_cul), ci((2 3))) (matrix(distancepers_moralcul), ci((2 3))), xline(0) xscale(range(-.1 .1))

*****Analysis Part II: Party identity moderation
***Producing Figure 3
reg moral_conviction_index ib5.message_neutralvsmoral##i.party_id i.mani_check2 if message_neutralvsmoral==2 | message_neutralvsmoral==5
margins, dydx(message_neutralvsmoral) over(party_id) post
est store moralmes

reg moral_conviction_index ib5.message_neutralvsmoral##i.party_id i.mani_check2 if message_neutralvsmoral==1 | message_neutralvsmoral==5
margins, dydx(message_neutralvsmoral) over(party_id) post
est store neutralmes

coefplot neutralmes moralmes, drop(_cons) levels (95 90) xline(0) xscale(range(-.3 .3))

**Regressions behind asterisks (*) in Figure 3
reg moral_conviction_index i.message_neutralvsmoral i.mani_check2 if party_id==1
reg moral_conviction_index i.message_neutralvsmoral i.mani_check2 if party_id==2
reg moral_conviction_index i.message_neutralvsmoral i.mani_check2 if party_id==3
reg moral_conviction_index i.message_neutralvsmoral i.mani_check2 if party_id==4

***Appendix 5. Partisan effects
**Figure A5.4.
reg im_extreme i.mani_check2 ib5.message_neutralvsmoral##i.party_id if message_neutralvsmoral==2 | message_neutralvsmoral==5
margins, dydx(message_neutralvsmoral) over(party_id) post
est store moralmes_ex

reg im_extreme i.mani_check2 ib5.message_neutralvsmoral##i.party_id if message_neutralvsmoral==1 | message_neutralvsmoral==5
margins, dydx(message_neutralvsmoral) over(party_id) post
est store neutralmes_ex

coefplot neutralmes_ex moralmes_ex, drop(_cons) levels (95 90) xline(0) 

**Figure A5.5.
reg distance_polleader i.mani_check2 ib5.message_neutralvsmoral##i.party_id if message_neutralvsmoral==2 | message_neutralvsmoral==5
margins, dydx(message_neutralvsmoral) over(party_id) post
est store moralmes_pol

reg distance_polleader i.mani_check2 ib5.message_neutralvsmoral##i.party_id if message_neutralvsmoral==1 | message_neutralvsmoral==5
margins, dydx(message_neutralvsmoral) over(party_id) post
est store neutralmes_pol

coefplot neutralmes_pol moralmes_pol, drop(_cons) levels (95 90) xline(0) xscale(range(-.4 .4))

**Figure A5.6.
reg distance_personalrelations i.mani_check2 ib5.message_neutralvsmoral##i.party_id if message_neutralvsmoral==2 | message_neutralvsmoral==5
margins, dydx(message_neutralvsmoral) over(party_id) post
est store moralmes_rel

reg distance_personalrelations i.mani_check2 ib5.message_neutralvsmoral##i.party_id if message_neutralvsmoral==1 | message_neutralvsmoral==5
margins, dydx(message_neutralvsmoral) over(party_id) post
est store neutralmes_rel

coefplot neutralmes_rel moralmes_rel, drop(_cons) levels (95 90) xline(0) xscale(range(-.3 .3))